<template>
  <div class="login-container">
    <div class="login-weaper  animated bounceInDown">
      <!-- <div class="login-left animate__animated animate__fadeInLeft">
        <img class="img" src="/img/logo.png" alt=""/>
        <p class="title">{{ website.title }}</p>
        <p>©{{ website.year }} {{ website.version }}</p>
      </div> -->
      <div class="login-border">
        <div class="login-main">
          <h4 class="login-title">{{ website.title }}</h4>
          <userLogin v-if="activeName === 'user'"></userLogin>
          <codeLogin v-else-if="activeName==='code'"></codeLogin>
          <thirdLogin v-else-if="activeName==='third'"/>
          <user-register v-else-if="activeName==='register'" @ok="activeName='user'"></user-register>
<!--          <div class="login-menu">
            <a href="#"
               @click.stop="activeName='user'">账号密码</a>
            <a href="#"
               @click.stop="activeName='code'">短信登录</a>
            <a
              href="#"
              @click.stop="activeName='third'">第三方登录</a>
            <a href="#" v-if="website.register"
               @click.stop="activeName='register'">用户注册</a>
          </div>-->
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import "@/styles/login.scss";
import userLogin from "./userlogin";
import codeLogin from "./codelogin";
import thirdLogin from './thirdlogin'
import userRegister from "@/page/login/userRegister";
import {mapGetters} from "vuex";

export default {
  name: "login",
  components: {
    userLogin,
    codeLogin,
    thirdLogin,
    userRegister
  },
  data() {
    return {
      activeName: "user",
      socialForm: {}
    };
  },
  watch: {
    $route: {
      handler() {
        const params = this.$route.query
        if (this.validatenull(params.state) && this.validatenull(params.code)) return

        this.socialForm.state = params.state
        this.socialForm.code = params.code

        const loading = this.$loading({
          lock: true,
          text: `登录中,请稍后。。。`,
          spinner: 'el-icon-loading'
        })
        this.$store.dispatch('LoginBySocial', this.socialForm).then(
          () => {
            loading.close()
            this.$router.push({ path: this.tagWel.value })
          }).catch(() => {
          loading.close()
        })
      },
      immediate: true
    }
  },
  computed: {
    ...mapGetters(["website"])
  }
};
</script>
